<template>
  <div class="app-container">
    <avue-crud
      :data="data"
      :option="option"
      v-model="addObj"
      :page="page"
      @search-change="searchChange"
      @size-change="sizeChange"
      @current-change="currentChange"
      @row-del="delRow"
    >
    </avue-crud>
  </div>
</template>

<script>
  import {getList,deleteInfo} from '@/api/alarmInformation'
  import { add, deleteType, edit } from '@/api/alarmTypeManagement'
    export default {
        name: "roleManagement",
        watch:{
            data() {
                // 对 Table 进行重新布局
                this.$nextTick(()=>{
                    this.$refs.crud.$refs.table.doLayout()
                })
            },
        },
        data() {
            return {
                addObj: {
                    attachs: [
                        {
                            fileName: "萨达",
                            time: "奥术大师"
                        }
                    ]
                },
                data: [],
                originPage:{
                    pageSize: 10,
                    currentPage: 1,
                    total: 10,
                },
                page: {
                    currentPage: 1,
                    pageSize: 10,
                    total: 20,
                    layout: "total,pager,prev, next",
                },

                option: {
                    labelWidth:120,
                    labelPosition:"left",
                    dialogEscape: false,
                    dialogClickModal: false,
                    dialogWidth: 800,
                    height: "auto",
                    calcHeight: 100,
                    searchShow: true,
                    index: true,
                    indexLabel: "序号",
                    searchMenuSpan:6,
                    indexWidth: 100,
                    refreshBtn: false,
                    searchBtn: true,
                    columnBtn: false,
                    addBtn: true,
                    menu: true,
                    delBtn: true,
                    editBtn: false,
                    align: "center",
                    column: [
                        {
                            label: "报警设备",
                            prop: "alarmDevice",
                            search:true,
                        },
                        {
                            label: "发生时间",
                            prop: "createTime",
                            search:true,
                            type:"date",
                            searchRange:true,
                            format: "yyyy-MM-dd",
                            valueFormat: "yyyy-MM-dd",
                        },
                        {
                            label: "报警地点",
                            prop: "alarmSite",
                        },
                        {
                            label: "报警内容",
                            prop: "content",
                        },{
                            label: "报警类型",
                            prop: "type",
                            type:"select",
                            search:true,
                            dicData:[
                                {label:'警告',
                                value:0
                               },{label:'报警',
                                    value:1
                                },{label:'事故',
                                    value:2
                                },]
                        },
                    ]
                },

            };
        },
        computed: {
        },
        methods: {
            initData() {
                this.page.pageNum=this.page.currentPage
                getList(this.page).then(res=>{
                    this.data = res.data.resultList;
                    this.page.total = res.data.total;
                })
            },
            searchChange(params, done) {
                console.log(params)
                this.page=this.originPage
                if(params.createTime){
                    params.startTime=params.createTime[0]+" 00:00:00"
                    params.endTime=params.createTime[1]+" 23:59:59"
                    delete params.createTime
                }
                this.page={...this.page,...params}
                console.log(this.page)
                this.initData();
                done()
            },
            delRow(scope){
              console.log(scope.id)
              this.$confirm('此操作将永久删除该报警类型信息, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                deleteInfo(scope.id).then(()=>{
                  this.initData();
                  this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                })
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                });
              });
            },
            sizeChange(val) {
                this.page.currentPage = 1;
                this.page.pageSize = val;
                this.initData();
            },

            currentChange(val) {
                this.page.currentPage = val;
                this.initData();
            },
        },
        mounted() {
             this.initData()
            // this.initDic()


        },


        created() {

        },

    };
</script>

<style lang="scss">

</style>
